package com.shqcjd.preinstallmobile.util;

import android.app.Activity;
import android.content.Intent;

import com.orhanobut.logger.Logger;
import com.shqcjd.preinstallmobile.app.MyApp;
import com.shqcjd.preinstallmobile.ui.activity.AnswerActivity;
import com.shqcjd.preinstallmobile.ui.activity.MainActivity;
import com.shqcjd.preinstallmobile.ui.activity.WaitingAnswerActivity;
import com.shqcjd.preinstallmobile.ui.activity.remote.PullVideoCallActivity;
import com.shqcjd.preinstallmobile.ui.activity.remote.PushVideoCallActivity;

import io.agora.AgoraAPI;
import io.agora.AgoraAPIOnlySignal;

/**
 * Created by sy on 2019/3/29.
 */

public class AgoraUtil {
    private static AgoraUtil instance;
    private Activity activity;
    private final AgoraAPIOnlySignal agoraAPIOnlySignal;

    public AgoraUtil(Activity activity) {
        this.activity = activity;
        agoraAPIOnlySignal = MyApp.the().getmAgoraAPI();
        if (activity instanceof MainActivity || activity instanceof WaitingAnswerActivity || activity instanceof AnswerActivity||activity instanceof PullVideoCallActivity ||activity instanceof PushVideoCallActivity) {//首页声网监听
        } else {
            addAnswerCallback();
        }
    }

    private void addAnswerCallback() {
        agoraAPIOnlySignal.callbackSet(new AgoraAPI.CallBack() {
            @Override
            public void onError(String s, int i, String s1) {
                Logger.e("Agora 信令onError s:" + s + " i:" + i + " s1:" + s1);
            }

            //收到对方呼叫时调用
            @Override
            public void onInviteReceived(String channelID, String account, int uid, String extra) {
                super.onInviteReceived(channelID, account, uid, extra);
                Logger.i("AgoraService：收到呼叫 房间:" + channelID + " 账号:" + account + " 备注:" + extra);
                Intent intent = new Intent(MyApp.getmContext(), AnswerActivity.class);
                intent.putExtra("channelID", channelID);
                intent.putExtra("callerId", account);//主叫方id
                intent.putExtra("info", extra);//主叫方id
                activity.startActivity(intent);

            }
        });
    }





}
